package client.material;

import client.common.vo.MaterialVO;

import java.util.List;

public class PagingModel {
    private int pageSize = 10; // 每页显示的行数
    private int currentPage = 1;
    private int totalRecords;
    private List<MaterialVO> data;
    
    public PagingModel(List<MaterialVO> allData) {
        this.totalRecords = allData.size();
        this.data = allData.subList((currentPage - 1) * pageSize, Math.min(currentPage * pageSize, totalRecords));
    }
    
    public void nextPage() {
        if (hasNextPage()) {
            currentPage++;
            updateData();
        }
    }
    
    public void prevPage() {
        if (hasPrevPage()) {
            currentPage--;
            updateData();
        }
    }
    
    private boolean hasNextPage() {
        return currentPage * pageSize < totalRecords;
    }
    
    private boolean hasPrevPage() {
        return currentPage > 1;
    }
    
    private void updateData() {
        // data = allData.subList((currentPage - 1) * pageSize, Math.min(currentPage * pageSize, totalRecords));
    }
    
    public List<MaterialVO> getData() {
        return data;
    }
    
    public int getCurrentPage() {
        return currentPage;
    }
    
    public int getTotalPages() {
        return (int) Math.ceil((double) totalRecords / pageSize);
    }
}